package fr.mywiki.view.web.struts.action.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;

/** Acts only as a menu for the administration of the application */
public class AdminHomeAction extends DispatchAction {
	/* The different kinds of directions */
	/** Go to the creation of user interface. */
	public static final String CREATE_ACCOUNT = "createAccount";
	/** Get the list of users */
	public static final String GET_ACCOUNTS = "getAccounts";
	/** Manage structure */
	public static final String MANAGE_STRUCTURE = "manageStructure";
	
	/**
	 * Displays the admin home page.
	 */
	public ActionForward display(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse arg3) {
		return mapping.findForward("display");
	}
	
	/**
	 * Reaches the part of the administration space dedicated to the function which the user clicked
	 * on.
	 */
	public ActionForward reach(ActionMapping mapping, ActionForm actionForm,
			HttpServletRequest request, HttpServletResponse arg3) {
		DynaActionForm form = (DynaActionForm) actionForm;
		Object redirection = form.get("redirectme");
		
		if(CREATE_ACCOUNT.equals(redirection))
			return mapping.findForward(CREATE_ACCOUNT);
		if(GET_ACCOUNTS.equals(redirection))
			return mapping.findForward(GET_ACCOUNTS);
		if(MANAGE_STRUCTURE.equals(redirection))
			return mapping.findForward(MANAGE_STRUCTURE);
		
		return mapping.findForward("display");
	}

	public String getPageName() {
		return "adminHome";
	}
}
